
const db = require("../utils/db")
const util = require("../utils/util")

async function add_user(id) {
    var sql = "Insert into user(user_id, name, avatar, authority, confirm_time) values(?,?,?,?,?)";
    var args = [id, "默认马甲", "http://lxtyin.ac.cn/img/cf.png", 5, util.datestring(new Date())];
    await db.query(sql, args);
}

async function get_user(id) {
    var sql = "Select * from user where user_id=?";
    var args = [id];
    return (await db.query(sql, args))[0];
}

async function update_user(id, name, avatar) {
    var sql = "update user set name=?, avatar=? where user_id=?";
    var args = [name, avatar, id];
    await db.query(sql, args);
}

module.exports = {
    add_user: add_user,
    get_user: get_user,
    update_user: update_user,
}
